home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: Character string
- Date: Thu, 11 Apr 96 14:45:13 GMT
- Organization: none
- Message-ID: <829233913snz@genesis.demon.co.uk>
- References: <4kil74$8i7@Tandem1.opennet.net.au>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <4kil74$8i7@Tandem1.opennet.net.au>
- george@opennet.net.au "Kenneth H Smith" writes:
-
- >How do I do a similar statement in C to the Pascal code:
- >
- >If Ch IN ['a','A'] THEN
- >
- >I want to execute a piece of code when a particular character is entered
- >from the keyboard.
- >
- >I know I can use if (ch=='a') && (ch=='A') but was looking for something
- >a little more ellegant.
-
- There is no direct equivalent although you could use a switch statement
- e.g.
-
- switch (ch) {
- case 'a':
- case 'A':
- /* Do something */
- break;
- default:
- /* Do something else */
- break;
- }
-
- This looks clumsy for a small number of cases but is quite effective for
- a larger number where you would probably put more than one case per line.
-
- For your 2 value example above you won't do much better than the if
- statement.
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-